package history.hot100;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;

// 406. 根据身高重建队列:https://leetcode-cn.com/problems/queue-reconstruction-by-height/
public class LeetCode_406 {
    public int[][] reconstructQueue(int[][] people) {
        Arrays.sort(people, new Comparator<int[]>() {
            @Override
            public int compare(int[] o1, int[] o2) {
                if (o1[0] != o2[0]) return o2[0] - o1[0];
                else return o1[1] - o2[1];
            }
        });
        List<int[]>ans = new ArrayList<>();
        for (int []preson : people) ans.add(preson[1],preson);
        return ans.toArray(new int[ans.size()][]);
    }
}
